package com.study.mall;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.math.BigDecimal;
import java.util.Arrays;

public class Demo {
    public static void main(String[] args) {
        double d1 = 0.1;
        double d2 = 0.2;
        double result = d1 + d2;
        System.out.println(result); //0.30000000000000004

        BigDecimal num1 = new BigDecimal("0.1");
        BigDecimal num2 = new BigDecimal("0.2");

        BigDecimal sum = num1.add(num2);
        BigDecimal product = num1.multiply(num2);

        System.out.println("Sum: " + sum); //Sum: 0.3
        System.out.println("Product: " + product);// Product: 0.02

        byte a = 127;
        byte b = 127;
        //b = a + b;// 报编译错误:cannot convert from int to byte
        b += a; // 等价于 b = (byte)(b + a);

        short s1 = 1;
        //s1 = s1 + 1;
    }

    @Test
    public void test2() {
        Integer a = 10;//Integer.valueOf(10)
        Integer b = 10;
        Integer c = 129;
        Integer d = 129;
        Integer e = new Integer(13);
        Integer f = new Integer(13);
        System.out.println(a == b); //true
        System.out.println(c == d);
        //false
        System.out.println(e == f);//false   new出来的对象是在堆里面地址值肯定不一样

        final int num = 2;
        //num = 23;

        final int[] arr = new int[num];
        arr[0] = 1;
        System.out.println(Arrays.toString(arr));
        //arr = new int[23];

    }

    @Test
    public void test1() {
        listFiles(new File("D:\\mypic"));
    }

    public static void listFiles(File dir) {
        for (File file : dir.listFiles()) {
            if (file.isDirectory()) {
                listFiles(file); // 递归调用
            } else {
                System.out.println(file.getName());
            }
        }
    }

    @Test
    public void test12() {
        File root = new File("D:\\mypic");
        listFiles(root, 0); // 初始层级 0
    }

    public static void listFiles(File dir, int level) {
        // 前缀缩进：每一层多两个空格
        String indent = "  ".repeat(level);

        for (File file : dir.listFiles()) {
            if (file.isDirectory()) {
                System.out.println(indent + "[DIR] " + file.getName());
                listFiles(file, level + 1); // 下一层目录，level+1
            } else {
                System.out.println(indent + file.getName());
            }
        }
    }


}
